﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace EmrDatastructure
{
    public class EmrContext : DbContext
    {
        public DbSet<EmrDemographic> Demographics { get; set; }
        public DbSet<EmrSmoking> Smoking { get; set; }
        public DbSet<EmrProblem> Problems { get; set; }
        public DbSet<EmrUser> Users { get; set; }

        public EmrContext()
        {
            ((IObjectContextAdapter)this).ObjectContext.ContextOptions.ProxyCreationEnabled = false;
            ((IObjectContextAdapter)this).ObjectContext.ContextOptions.LazyLoadingEnabled = false;
            this.Configuration.AutoDetectChangesEnabled = false;
        }
     }
    public class EmrContextInitializerDropCreate : DropCreateDatabaseAlways<EmrContext>
    {
    }
    public class EmrContextInitializerIfNotExists : CreateDatabaseIfNotExists<EmrContext>
    {        
        protected override void Seed(EmrContext context)
        {
            EmrDemographic emrDemographic = new EmrDemographic();
            emrDemographic.Id = "Seed";
            emrDemographic.PreferredLanguage = "1";
            emrDemographic.Gender = "2";
            emrDemographic.Race = "3";
            emrDemographic.Ethnicity = "4";
            emrDemographic.DateOfBirth = new DateTime(1970, 5, 6);
            emrDemographic.FirstName = "7";
            emrDemographic.LastName = "8";
            context.Demographics.Add(emrDemographic);

            EmrProblem emrProblem = new EmrProblem();
            emrProblem.DateDiagnosed = DateTime.Now;
            emrProblem.Description = "Seed Problem";
            emrProblem.EmrDemographicId = "Seed";
            emrProblem.Snomed_CT = "Some CT code";
            emrProblem.Status = "Active";
            context.Problems.Add(emrProblem);

            EmrSmoking emrSmoking = new EmrSmoking();
            emrSmoking.EmrDemographicId = "Seed";
            emrSmoking.Status = 1;
            context.Smoking.Add(emrSmoking);


            EmrDemographic emrDemographic1 = new EmrDemographic();
            emrDemographic1.Id = "Set1";
            emrDemographic1.PreferredLanguage = "English";
            emrDemographic1.Gender = "Female";
            emrDemographic1.Race = "White";
            emrDemographic1.Ethnicity = "Not Hispanic or Latino";
            emrDemographic1.DateOfBirth = new DateTime(1952, 5, 26);
            emrDemographic1.FirstName = "First1";
            emrDemographic1.LastName = "Last1";
            context.Demographics.Add(emrDemographic1);

            EmrDemographic emrDemographic2 = new EmrDemographic();
            emrDemographic2.Id = "Set2";
            emrDemographic2.PreferredLanguage = "Japanese";
            emrDemographic2.Gender = "Female";
            emrDemographic2.Race = "Asian";
            emrDemographic2.Ethnicity = "Not Hispanic or Latino";
            emrDemographic2.DateOfBirth = new DateTime(1945, 4, 30);
            emrDemographic2.FirstName = "First2";
            emrDemographic2.LastName = "Last2";
            context.Demographics.Add(emrDemographic2);

            EmrDemographic emrDemographic3 = new EmrDemographic();
            emrDemographic3.Id = "Set3";
            emrDemographic3.PreferredLanguage = "French";
            emrDemographic3.Gender = "Male";
            emrDemographic3.Race = "Asian";
            emrDemographic3.Ethnicity = "Not Hispanic or Latino";
            emrDemographic3.DateOfBirth = new DateTime(1988, 2, 27);
            emrDemographic3.FirstName = "First3";
            emrDemographic3.LastName = "Last3";
            context.Demographics.Add(emrDemographic3);

            EmrProblem emrProblem1 = new EmrProblem();
            emrProblem1.DateDiagnosed = new DateTime(2010, 5, 2);
            emrProblem1.Description = "Cerebrovascular Accident";
            emrProblem1.EmrDemographicId = "Set1";
            emrProblem1.Snomed_CT = "230690007";
            emrProblem1.Status = "Active";
            context.Problems.Add(emrProblem1);

            EmrProblem emrProblem2 = new EmrProblem();
            emrProblem2.DateDiagnosed = new DateTime(2010, 6, 24);
            emrProblem2.Description = "Recurrent Urinary Tract Infection";
            emrProblem2.EmrDemographicId = "Set1";
            emrProblem2.Snomed_CT = "197927001";
            emrProblem2.Status = "Resolved";
            context.Problems.Add(emrProblem2);

            EmrProblem emrProblem3 = new EmrProblem();
            emrProblem3.DateDiagnosed = new DateTime(2010, 4, 4);
            emrProblem3.Description = "Chronic Obstructive Lung Disease";
            emrProblem3.EmrDemographicId = "Set1";
            emrProblem3.Snomed_CT = "13645005";
            emrProblem3.Status = "Active";
            context.Problems.Add(emrProblem3);

            EmrProblem emrProblem4 = new EmrProblem();
            emrProblem4.DateDiagnosed = new DateTime(2010, 3, 30);
            emrProblem4.Description = "Essential Hypertension";
            emrProblem4.EmrDemographicId = "Set1";
            emrProblem4.Snomed_CT = "59621000";
            emrProblem4.Status = "Active";
            context.Problems.Add(emrProblem4);

            EmrUser emrUser = new EmrUser();
            emrUser.UserName = "a";
            emrUser.Email = "a@a.com";
            emrUser.Password = "a";
            context.Users.Add(emrUser);  
        }         
    }
}
